﻿using System.Data.Linq;
using System.Linq;
using UniMana.Data;
using System;

namespace UniMana.Data
{
    public static class ReportStudent_CourseData_Chi
    {
        public static IQueryable Student_Course(this  Table<Catalogue_Course> cataCourse,
                       Table<Training_Student_Class> student_Class,
                       Table<Training_Student> student)
        {
            var view = from t in student
                       join t0 in student_Class on t.Training_StudentKey equals t0.Training_StudentKey
                       join t1 in cataCourse on new { Catalogue_CourseKey = Convert.ToInt32(t0.Catalogue_CourseKey) } equals new { Catalogue_CourseKey = t1.Catalogue_CourseKey }
                       group t1 by new
                       {
                           t1.Catalogue_CourseKey,
                           t1.Name
                       } into g
                       orderby
                         g.Key.Catalogue_CourseKey
                       select new
                       {
                           Catalogue_CourseKey = (System.Int32?)g.Key.Catalogue_CourseKey,
                           g.Key.Name,
                           TongCong = (Int64?)g.Count()
                       };
            return view;
        }
    }
}